package com.fahai.web.service.impl;

import com.fahai.common.PageVo;
import com.fahai.web.dao.UserGroupDao;
import com.fahai.web.entity.UserGroup;
import com.fahai.web.service.SysGroupService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Created by sky on 17/5/9.
 */
@Service
public class SysGroupServiceImpl implements SysGroupService {

    @Autowired
    UserGroupDao userGroupDao;

    /**
     * 查找所有公司部门组名称
     * @return
     */
    @Override
    public List<UserGroup> findUserGroupList(){
        List<UserGroup> userGroupEntities = userGroupDao.selectByGroupList();
        return userGroupEntities;
    }

    /**
     * 修改部门名称
     * @param userGroup
     */
    @Override
    public void updateUserGroup(UserGroup userGroup){
        userGroupDao.updateByPrimaryKeySelective(userGroup);
    }

    /**
     * 添加新部门
     * @param userGroup
     */
    @Override
    public void saveUserGroup(UserGroup userGroup){
        userGroupDao.insert(userGroup);
    }


    /**
     * 删除部门
     * @param userGroup
     */
    @Override
    public void deleteUserGroup(UserGroup userGroup){
        userGroupDao.deleteByPrimaryKey(userGroup);
    }


    /**
     * 查找所有公司部门组名称分页
     * @return
     */
    @Override
    public PageVo findUserGroupList(PageVo pageVo){
        Page<HashMap<String,Object>> page = PageHelper.startPage(pageVo.getPageNum(), pageVo.getPageSize());
        List<UserGroup> userGroupEntities = userGroupDao.selectByGroupList();
        pageVo.setResult(userGroupEntities);
        pageVo.setTotal(new Long(userGroupDao.selectCount(new UserGroup())));
        return pageVo;
    }
}
